package com.feifan.utils;

/**
 * @author Donald
 * @create 2019-04-29 22:29
 * 字符串工具类
 */
public class StringUtils {

    private StringUtils() {}

    public static boolean isNull( String str )
    {
        return null == str;
    }

    public static boolean isNullOrEmpty( String str )
    {
        return isNull(str) || str.length() == 0;
    }

    public static boolean isPhoneNumber( String phoneNumber )
    {
        if ( isNullOrEmpty(phoneNumber) )
        {
            return false;
        }
        return phoneNumber.matches("1[0-9]{10}");
    }

    public static boolean isEmail( String email )
    {
        if ( isNullOrEmpty(email))
        {
            return false;
        }
        return email.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    }

    public static boolean isNumber( String number )
    {
        if ( isNullOrEmpty( number) )
        {
            return false;
        }
        return number.matches("[+-]?[0-9]+\\.[0-9]+");
    }

    public static boolean isQQ( String QQ )
    {
        if ( isNullOrEmpty( QQ ) )
        {
            return false;
        }
        return QQ.matches("[1-9]\\d{4,9}]");
    }

    public static boolean isAge( String age )
    {
        if ( isNullOrEmpty( age ) )
        {
            return false;
        }
        return age.matches("1[012][0-9]|[1-9][0-9]");
    }

    public static boolean isChinese( String china )
    {
        if ( isNullOrEmpty( china ) )
        {
            return false;
        }
        return china.matches("[\\u4e00-\\u9fa5]");
    }

    public static boolean isUsername( String username )
    {
        if ( isNullOrEmpty( username ) )
        {
            return false;
        }
        return username.matches("[A-Za-z](\\w|\\.){5,16}");
    }

    public static boolean isPeopleNumber( String peopleNumber )
    {
        if ( isNullOrEmpty( peopleNumber ) )
        {
            return false;
        }
        return peopleNumber.matches("\\d{18}[a-zA-Z0-9]");
    }

    public static boolean isPassword( String password )
    {
        if ( isNullOrEmpty( password ) )
        {
            return false;
        }
        return password.matches("[!@#$%^&*a-zA-Z0-9_.]{5,19}");
    }

    public static boolean isYan( String yan )
    {
        if ( isNullOrEmpty( yan ) )
        {
            return false;
        }
        return yan.matches("[a-zA-Z0-9]{6}");
    }

    public static boolean isStartOrEndWithEmpty( String targe )
    {
        if ( isNullOrEmpty( targe ) )
        {
            return false;
        }
        return targe.matches("^(\\s+)|(\\s+)$");
    }


    public static void main(String[] args) {
        System.out.println(isEmail("9450-w2@sss.d")+""+isAge("89"));
        System.out.println(isStartOrEndWithEmpty("  ll"));
    }
}
